<!-- src/components/LoadingSpinner.vue -->
<template>
    <div v-if="isLoading" class="spinner">
        <!-- 加载动画内容，例如一个旋转的图标 -->
        <div class="lodIng-box">
            <div class="icon-box">
                <img :src="logIcon" alt="" srcset="">
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, defineExpose } from 'vue';
import logIcon from '@/assets/images/log.jpg'
const isLoading = ref(false);
const startLoading = () => {
    isLoading.value = true;
}
const stopLoading = () => {
    isLoading.value = false;
}
defineExpose({
    startLoading,
    stopLoading
})
</script>

<style scoped lang="scss">
@keyframes loaderspin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg)
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg)
    }
}

@-webkit-keyframes loaderspin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg)
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg)
    }
}

@keyframes loaderpulse {
    0% {
        transform: scale(1)
    }

    100% {
        transform: scale(1.2)
    }
}

.spinner {
    /* 加载动画样式 */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;

    .lodIng-box {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 140px;
        height: 140px;
        border: 5px solid #ebebec;
        border-radius: 50%;

        .icon-box {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 80px;

            img {
                max-width: 100%;
                height: auto;
                animation: loaderpulse alternate 900ms infinite;
            }
        }
    }

    .lodIng-box::before {
        position: absolute;
        content: "";
        display: block;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 140px;
        height: 140px;
        border-top: 4px solid #88211a;
        border-radius: 50%;
        animation: loaderspin 1.8s infinite ease-in-out;
        border-color: #88211a;
    }
}
</style>